package com.foreknow.demo11;

public class UserManager {
    String[] name = new String[2];
    String[] pass = new String[2];

    public void register(String username,String password) throws CustomException{
        //查看字符串String的长度
        int nLength = username.length();
        int npass = password.length();
        //验证用户名和密码是否为空
        if (username.equals("") || password == null) {
            throw new CustomException("输入的用户名和密码为空");
        }
        //判断用户名的长度
        if (nLength < 6 || nLength > 14) {
            throw new CustomException("用户名的长度不符合规范");
        }
        //判断密码的长度
        if (npass < 8 || npass > 16) {
            throw new CustomException("密码的长度不符合规范");
        }

        for (int i= 0;i<name.length;i++) {
            if (name[i] == null && pass[i] == null) {
                name[i] = username;
                pass[i] = password;
                System.out.println("注册成功！");
                return;  //方法中遇到return，方法就结束了
            }
        }
        throw new CustomException("用户已经达到上限！无法注册");
    }

    public static void main(String[] args) {
        UserManager manager = new UserManager();
        try {
            manager.register("tom","55667788");
        } catch (CustomException e) {
            e.printStackTrace();
        }
        System.out.println("1111111111111111111111111111");
    }
}




















